package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.sun.org.apache.bcel.internal.generic.GETSTATIC;

import br.trainee.web.util.ResponseWrapper;

public class MenuTag extends BodyTagSupport{

	private String idMenu;
	private String customClass;
	private String disabled;
	private String position;
	private String icons;

	@Override
	public int doEndTag() throws JspException {
		
		JspWriter saida = pageContext.getOut();
		String corpoMenu = getBodyContent().getString();
		
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();		
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("idMenu", idMenu);
		request.setAttribute("customClass", customClass);
		request.setAttribute("disabled", disabled);
		request.setAttribute("position", position);
		request.setAttribute("icons", icons);
		request.setAttribute("corpoMenu", corpoMenu);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/menu.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		}catch(IOException io){
			
			io.printStackTrace();
			
		} catch (ServletException s) {
			
			s.printStackTrace();
		}
		
		return super.doEndTag();
	}

	public String getIdMenu() {
		return idMenu;
	}

	public void setIdMenu(String idMenu) {
		this.idMenu = idMenu;
	}

	public String getCustomClass() {
		return customClass;
	}

	public void setCustomClass(String customClass) {
		this.customClass = customClass;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getIcons() {
		return icons;
	}

	public void setIcons(String icons) {
		this.icons = icons;
	}
	
}
